﻿@model Von.Web.Models.LoginViewModel

<h2>@ViewData["Title"]</h2>
@Html.Partial("~/Views/_StatusMessage.cshtml", Model?.StatusMessage)
<div class="row">
    <div class="col-md-4">
        <section>
            <form asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
                <h4>登录系统</h4>
                <hr />
                <div asp-validation-summary="All" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="LoginName"></label>
                    <input asp-for="LoginName" class="form-control" placeholder="用户名/手机号码/邮箱" />
                    <span asp-validation-for="LoginName" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="Password"></label>
                    <input asp-for="Password" class="form-control" type="password" />
                    <span asp-validation-for="Password" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <label asp-for="RememberMe">
                            <input asp-for="RememberMe" onclick="rememberLogin(this)"/>
                            @Html.DisplayNameFor(m => m.RememberMe)
                        </label>
                    </div>
                </div>
                <div class="btn-group-vertical">
                    <button class="btn btn-primary" type="submit">登录</button>
                    <button class="btn btn-link" asp-action="ForgotPassword" >忘记密码！</button>
                    @if(Statement.App.AppSetting["CanRegist"] == null || Statement.App.AppSetting["CanRegist"].ToString() != "false") {
                    <a class="btn btn-link" onclick="ShowRegist()">注册新用户</a>
                    }
                </div>
            </form>
        </section>
    </div>
</div>

<div class="modal fade" id="register" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="ModalLabel">注册用户</h3>
            </div>
            <div class="modal-body">
                @Html.Partial("/Views/Account/RegisterView.cshtml", new Von.Web.Models.RegisterViewModel())
            </div>
            <div class="modal-footer">
                <div class="form-group">
                    <input type="button" value="保存" onclick="Regist()" class="btn btn-default" />
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<script type="text/javascript">
    function ShowRegist() {
        SetRegisterData(null);
        $('#register').modal('show');
    }
    function Regist() {
        var msg = CheckRegisterData();
        if (msg != "") return SysWarning(msg);
        var data = {};
        GetRegisterData(data);
        AjaxPostData("/Account/RegistUser", data, function (result) { if (result = true) window.location.reload(); });
    }
    function rememberLogin(e) {
        von = new VonStorage();
        if ($(e).prop('checked')) {
            von.write("loginname", $("#LoginName").val());
            von.write("loginpwd", $("#Password").val());
        } else {
            von.remove("loginname");
            von.remove("loginpwd");
        }
    }
</script>
@section Scripts {
    @await Html.PartialAsync("_ValidationScriptsPartial")
}

@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "LoginInit",
    @<script>
        $(function () {
            von = new VonStorage();
            var key = von.read("loginname");
            if (key != null) {
                $("#LoginName").val(key);
                $("#Password").val(von.read("loginpwd"));
            }
        });
    </script>
)